package com.qys.livesMall.shop.controller.app;

import com.qys.livesMall.common.result.R;
import com.qys.livesMall.finance.model.dto.AccountDetailSearch;
import com.qys.livesMall.finance.model.dto.AccountInOut;
import com.qys.livesMall.finance.service.FinanceShopAccountDetailService;
import com.qys.livesMall.framework.utils.SecurityUtils;
import com.qys.livesMall.framework.view.QysPage;
import com.qys.livesMall.shop.modal.dto.shop.balance.ShopBalanceDetailSearch;
import com.qys.livesMall.shop.modal.vo.ShopBalanceDetailVO;
import com.qys.livesMall.shop.service.H2ShopBalanceDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *app-店铺余额明细
 *
 * @author
 * @since 2023-06-06
 */
@RestController
@RequestMapping("/app/shop/Balance/detail/")
public class AppH2ShopBalanceDetailController {

    @Autowired
    private H2ShopBalanceDetailService balanceDetailService;

    @Autowired
    private FinanceShopAccountDetailService financeShopAccountDetailService;

    /**
     * 列表
     * @param search
     * @return
     */
    @PostMapping("list")
    public R<QysPage<ShopBalanceDetailVO>> list(@RequestBody AccountDetailSearch search){
        search.setUserId(SecurityUtils.getUserId());
        if (search.getPageSize()>=50){
            return R.fail("Page out max length");
        }
        return R.ok(balanceDetailService.list(search));
    }


    /**
     * 保证金资金明细列表
     * @param search
     * @return
     */
    @PostMapping("emList")
    public R<QysPage<ShopBalanceDetailVO>> emList(@RequestBody AccountDetailSearch search){
        search.setUserId(SecurityUtils.getUserId());
        if (search.getPageSize()>=50){
            return R.fail("Page out max length");
        }
        return R.ok(balanceDetailService.emlist(search));
    }


    /**
     * 统计
     * @param search
     * @return
     */
    @PostMapping("sum")
    public R<AccountInOut> sum(@RequestBody AccountDetailSearch search){
        search.setUserId(SecurityUtils.getUserId());
        AccountInOut inOut=financeShopAccountDetailService.sum(search);
        if (inOut==null){
            inOut=new AccountInOut();
        }
        return R.ok(inOut);
    }
}
